from django import http
from django.shortcuts import render

# Create your views here.
from django.views import View
from verifications.libs.captcha.captcha import captcha
from django_redis import get_redis_connection

class ImageCodeView(View):
    """图形验证码"""

    def get(self,request,uuid):

        # 生成验证码
        text,image = captcha.generate_captcha()
        # 保存验证码
        redis_conn = get_redis_connection('verify_code')
        # redis_conn.setex('key','expires','value')
        redis_conn.setex('img_%s' % uuid,300,text)
        # 响应验证码
        return http.HttpResponse(image,content_type='image/jpg')

